﻿Imports System.Data.SqlClient
Imports DTO

Public Class NhanVienDao

    Public Shared Function LayDSDanhSach() As SqlDataAdapter
        Dim dt As New DataTable
        Dim cn As SqlConnection = DataProvider.ConnectioData
        Dim cmd As SqlCommand = DataProvider.CommandData("sp_laythongtinnhanvien", cn)

        Dim da As New SqlDataAdapter(cmd)
        cn.Close()
        Return da
    End Function

    Public Shared Function LayDanhSach() As DataTable
        Dim dt As New DataTable
        Dim cn As SqlConnection = DataProvider.ConnectioData
        Dim cmd As SqlCommand = DataProvider.CommandData("sp_laythongtinnhanvien", cn)

        Dim da As New SqlDataAdapter(cmd)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Shared Sub ThemNV(ByVal nv As NhanVienDto)

        Dim cn As SqlConnection = DataProvider.ConnectioData
        Dim cmd As SqlCommand = DataProvider.CommandData("sp_themnhanvien", cn)

        cmd.Parameters.Add("@manv", SqlDbType.NVarChar)
        cmd.Parameters("@manv").Value = nv.MaNV

        cmd.Parameters.Add("@tennv", SqlDbType.NVarChar)
        cmd.Parameters("@tennv").Value = nv.TenNV

        cmd.Parameters.Add("@gioitinh", SqlDbType.Bit)
        cmd.Parameters("@gioitinh").Value = nv.GioiTinh

        cmd.Parameters.Add("@ngaysinh", SqlDbType.Date)
        cmd.Parameters("@ngaysinh").Value = nv.NgaySinh

        cmd.Parameters.Add("@quequan", SqlDbType.NVarChar)
        cmd.Parameters("@quequan").Value = nv.QueQuan

        cmd.Parameters.Add("@dantoc", SqlDbType.NVarChar)
        cmd.Parameters("@dantoc").Value = nv.DanToc

        cmd.Parameters.Add("@cmnd", SqlDbType.NVarChar)
        cmd.Parameters("@cmnd").Value = nv.CMND

        cmd.Parameters.Add("@ngaycap", SqlDbType.Date)
        cmd.Parameters("@ngaycap").Value = nv.NgayCap

        cmd.Parameters.Add("@noicap", SqlDbType.NVarChar)
        cmd.Parameters("@noicap").Value = nv.NoiCap

        cmd.Parameters.Add("@trinhdo", SqlDbType.NVarChar)
        cmd.Parameters("@trinhdo").Value = nv.TrinhDo

        cmd.Parameters.Add("@diachi", SqlDbType.NVarChar)
        cmd.Parameters("@diachi").Value = nv.DiaChi

        cmd.Parameters.Add("@dienthoai", SqlDbType.NVarChar)
        cmd.Parameters("@dienthoai").Value = nv.DienThoai


        cmd.Parameters.Add("@ngayvaolam", SqlDbType.Date)
        cmd.Parameters("@ngayvaolam").Value = nv.NgayVaoLam

        cmd.Parameters.Add("@mabp", SqlDbType.Int)
        cmd.Parameters("@mabp").Value = nv.MaBP

        cmd.Parameters.Add("@macv", SqlDbType.Int)
        cmd.Parameters("@macv").Value = nv.MaCV

        cmd.Parameters.Add("@tongiao", SqlDbType.NVarChar)
        cmd.Parameters("@tongiao").Value = nv.TonGiao

        cmd.ExecuteNonQuery()

        cn.Close()

    End Sub

    Public Shared Sub SuaNV(ByVal nv As NhanVienDto)

        Dim cn As SqlConnection = DataProvider.ConnectioData
        Dim cmd As SqlCommand = DataProvider.CommandData("sp_suanhanvien", cn)

        cmd.Parameters.Add("@manv", SqlDbType.NVarChar)
        cmd.Parameters("@manv").Value = nv.MaNV

        cmd.Parameters.Add("@tennv", SqlDbType.NVarChar)
        cmd.Parameters("@tennv").Value = nv.TenNV

        cmd.Parameters.Add("@gioitinh", SqlDbType.Bit)
        cmd.Parameters("@gioitinh").Value = nv.GioiTinh

        cmd.Parameters.Add("@ngaysinh", SqlDbType.Date)
        cmd.Parameters("@ngaysinh").Value = nv.NgaySinh

        cmd.Parameters.Add("@quequan", SqlDbType.NVarChar)
        cmd.Parameters("@quequan").Value = nv.QueQuan

        cmd.Parameters.Add("@dantoc", SqlDbType.NVarChar)
        cmd.Parameters("@dantoc").Value = nv.DanToc

        cmd.Parameters.Add("@cmnd", SqlDbType.NVarChar)
        cmd.Parameters("@cmnd").Value = nv.CMND

        cmd.Parameters.Add("@ngaycap", SqlDbType.Date)
        cmd.Parameters("@ngaycap").Value = nv.NgayCap

        cmd.Parameters.Add("@noicap", SqlDbType.NVarChar)
        cmd.Parameters("@noicap").Value = nv.NoiCap

        cmd.Parameters.Add("@trinhdo", SqlDbType.NVarChar)
        cmd.Parameters("@trinhdo").Value = nv.TrinhDo

        cmd.Parameters.Add("@diachi", SqlDbType.NVarChar)
        cmd.Parameters("@diachi").Value = nv.DiaChi

        cmd.Parameters.Add("@dienthoai", SqlDbType.NVarChar)
        cmd.Parameters("@dienthoai").Value = nv.DienThoai


        cmd.Parameters.Add("@ngayvaolam", SqlDbType.Date)
        cmd.Parameters("@ngayvaolam").Value = nv.NgayVaoLam

        cmd.Parameters.Add("@mabp", SqlDbType.Int)
        cmd.Parameters("@mabp").Value = nv.MaBP

        cmd.Parameters.Add("@macv", SqlDbType.Int)
        cmd.Parameters("@macv").Value = nv.MaCV

        cmd.Parameters.Add("@tongiao", SqlDbType.NVarChar)
        cmd.Parameters("@tongiao").Value = nv.TonGiao

        cmd.ExecuteNonQuery()

        cn.Close()

    End Sub

    Public Shared Sub XoaNV(ByVal manv As String)

        Dim cn As SqlConnection = DataProvider.ConnectioData
        Dim cmd As SqlCommand = DataProvider.CommandData("sp_xoanhanvien", cn)

        cmd.Parameters.Add("@manv", SqlDbType.NVarChar)
        cmd.Parameters("@manv").Value = manv

        cmd.ExecuteNonQuery()

        cn.Close()

    End Sub
End Class
